Click here to return to the HDL Reference Guide. (last edit: 24. september 2012)

Access (VHDL)

A data type which allows for dynamic memory allocation, equivalent to pointers in C or Pascal. Used to model large memories.
The type Line in package TEXTIO is an access type.
An incomplete type declaration is used to permit recursively defined data structures, e.g. linked lists.

Syntax

  type NewName is access DataType;
  type IncompleteTypeName;
          

Placement

The Access Type can be placed at the below shown locations.
  PACKAGE Pack IS
    ... 
  END PACKAGE Pack;
  PACKAGE BODY Pack IS
    ... 
  END PACKAGE BODY Pack;
  Blk:BLOCK 
    ... 
  BEGIN 
    ... 
  END BLOCK Blk;
  ENTITY Ent IS
    ... 
  BEGIN 
    ... 
  END ENTITY Ent;
  ARCHITECTURE Arc OF Ent IS
    ... 
  BEGIN 
    ... 
  END ARCHITECTURE Arc;
  CONFIGURATION Conf OF Ent IS
    ... 
  END CONFIGURATION Conf;
  Proc:PROCESS(...) 
    ... 
  BEGIN 
    ... 
  END PROCESS Proc;
  PROCEDURE P(...) IS
    ... 
  BEGIN 
    ... 
  END PROCEDURE P;
  FUNCTION F(...) RETURN Tp IS
    ... 
  BEGIN
    ... 
  END FUNCTION F;

Rules

Only variables can be of access type, and they must point to a value allocated dynamically using new (not to another variable).
An access variable is initialised to the value null.
A procedure DEALLOCATE(Ptr) is implicitly defined and can be called to release the storage allocated using new.

Things to remember

VHDL suffers from dangling pointers. If you copy a pointer then deallocate the memory, the copied pointer still points to the now deallocated location.

Synthesis

Not synthesizable.

Tips

Can be used to reduce the amount of memory needed to simulate a large memory by only allocating host computer memory when needed.

Example

  type Link; -- Incomplete type declaration
  type Item is record
    Data: Std_logic_vector(7 downto 0);
    NextItem: Link;
  end record;
  type Link is access Item;
  variable StartOfList, Ptr: Link;

  -- Add item to start of list
  Ptr := new Item; -- Allocate storage
  Ptr.Data := "01010101";
  Ptr.NextItem := StartOfList; -- Link item into list
  StartOfList := Ptr;

  -- Delete entire list
  while StartOfList /= null loop
    Ptr := StartOfList.NextItem;
    DEALLOCATE(StartOfList);
    StartOfList := Ptr;
  end loop;
          

See Also

New, Type, Null, Record